import Vue from 'vue'
import Vuex from 'vuex'
import App from '@/components/app'
import Router from 'vue-router'
import router from '@/router'
import store from '@/store'
import axios from 'axios'
import VueLazyload from 'vue-lazyload'
Vue.prototype.$http = axios
Vue.config.productionTip = false
require('@/assets/styles/common.scss')
require('@/assets/fonts/iconfont.js')
require('@/assets/styles/_layer.scss')
import layer from 'vue-layer-mobile'
Vue.use(Vuex)
Vue.use(layer)
Vue.use(Router)
Vue.use(VueLazyload, {
  preLoad: 2,
  // error: require('./images/error.png'),
  loading: '',
  attempt: 1,
  lazyComponent: true
})

/* eslint-disable no-new */
window.APP = new Vue({
  store: new Vuex.Store(store),
  router: new Router(router),
  render: h => h(App)
})

import $http from '@/api'
let redirect = location.href
$http.getLogin({redirect: redirect})
.then(res => {
  if (res.code === 9999) {
    location.href = 'http://wx.ejiamart.com/api/i/account/login/?redirect=' + encodeURIComponent(redirect)
  } else {
    // 将vue实例挂载到这里，避免重复请求
    window.APP.$mount('#app')
  }
})

// window.APP.$mount('#app')
